#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<map>
using namespace std;

map<char,float> cpm = {{'C',12.01},{'H',1.008},{'O',16.00},{'N',14.01}};

bool isChar(char ch){
    return (ch>='A'&&ch<='Z') ||(ch>='a'&&ch<='z');
}

float getAns(string s){
    float ans = 0;
    size_t i=0;
    while(i<s.size()){
        if(isChar(s[i])){
            char element = s[i];
            i++;
            if(i<s.size() && !isChar(s[i])){
                int count = 0;   
                while(i<s.size() && !isChar(s[i])){
                    count = count*10 + (s[i] - '0');
                    i++;
                }
                ans += cpm[element] * count;
            } else {
                ans += cpm[element];
            }
        }else {
            i++;
        }
    }

    return ans;
}

int main(){
    int n;
    cin>>n;
    string s;
    while(n--){
        cin>>s;
        printf("%.3f\n",getAns(s));
    }
    return 0;
}